﻿@model Auction_Intranet.Models.AddRUUserModel

@{
    ViewBag.Title = "Add RU User";
    Layout = "~/Views/Shared/_LayoutAdmin.cshtml";
}

<h2>Add RU user to Auction site</h2>

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>Add RU user</legend>

        <div class="editor-label">
            @Html.LabelFor(model => model.username)
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.username, new { @class = "add-ru-user-input", placeholder = "username" })
            @Html.ValidationMessageFor(model => model.username)

        <div class="editor-field invite-group-form-input">            
        </div>
        </div>
        <p>
            <input type="submit" value="Create" />
        </p>
    </fieldset>
}

<div>
    @Html.ActionLink("Back to List", "Users")
</div>

<script type="text/javascript">

    $(function () {

        $("input.add-ru-user-input").autocomplete({
            source: function (request, response) {
                $.ajax({
                    type: "GET",
                    contentType: "application/json; charset=utf-8",
                    url: "/Admin/CollectUsernames/",
                    data: { query: request.term },
                    dataType: "json",
                    success: function (data) {
                        response($.map(data, function (item) {
                            return { label: item.name + " (" + item.username + ")", value: item.username };
                        }))
                    }
                });
            },
            minLength: 3
        });

    });

</script>